package cn.didi.feidi.androidorder.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.zxing.WriterException;
import com.google.zxing.encoding.EncodingHandler;

import cn.didi.feidi.androidorder.R;


public class ScanResultActivity extends AppCompatActivity {
    private TextView resultTextView;
    private EditText qrStrEditText;
    private ImageView qrImgImageView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scan_result);
//        System.out.println("执行到C");



        resultTextView = (TextView) this.findViewById(R.id.tv_scan_result);
        qrStrEditText = (EditText) this.findViewById(R.id.et_qr_string);
        qrImgImageView = (ImageView) this.findViewById(R.id.iv_qr_image);

        /*输出结果*/
        Intent intent = getIntent();
        String scanResult = intent.getStringExtra("result");
        resultTextView.setText(scanResult);

//        生成二维码
        Button generateQRCodeButton = (Button) this.findViewById(R.id.btn_add_qrcode);
        generateQRCodeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                 String contentString = qrStrEditText.getText().toString();
                 if (!contentString.equals("")) {

                     Bitmap qrCodeBitmap = EncodingHandler.createQRCode(contentString, 350);
                     qrImgImageView.setImageBitmap(qrCodeBitmap);
                 }else {
                     Toast.makeText(ScanResultActivity.this, "输入为空", Toast.LENGTH_SHORT).show();
                 }
                } catch (WriterException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
    }
//    @Override
//    protected void onActivityResult(int requestCode, int resultCode, Intent data){
//            super.onActivityResult(requestCode, resultCode, data);
//            if (resultCode == RESULT_OK) {
//                Bundle bundle = data.getExtras();
//                String scanResult = bundle.getString("result");
//                resultTextView.setText(scanResult);
//            }
//        }

}
